package com.bknow.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.bknow.mapper.ArticleMapper;
import com.bknow.model.ArticleInfo;
import com.bknow.model.CommentInfo;
import com.bknow.model.PageBean;
import com.bknow.model.SaveLoveInfo;

@Service
public class ArticleService {

	@Autowired
	private ArticleMapper ArticleMapper;

	public List<ArticleInfo> getAllArticle() {
		return ArticleMapper.getAllArticle();
}

	public List<CommentInfo> getCommentByArtiId(Integer articleId) {
		return ArticleMapper.getCommentByArtiId(articleId);
	}

	public int addComment(CommentInfo info) {
		return ArticleMapper.addComment(info);
	}

	public CommentInfo findCommentById(Integer commentId) {
		return ArticleMapper.findCommentById(commentId);
	}

	public int queryCommentTotal(Integer articleId) {
		return ArticleMapper.queryCommentTotal(articleId);
	}

	public int updateCommentTotal(int i,Integer articleId) {
		 return ArticleMapper.updateCommentTotal(i,articleId);
	}

	public List<SaveLoveInfo> getLoveByuId(Integer uId) {
		return ArticleMapper.getLoveByuId(uId);
	}

	public int queryLoveIsExist(Integer uId, Integer articleId) {
		return ArticleMapper.queryLoveIsExist(uId,articleId);
	}

	public int addLove(int i, Integer uId, Integer articleId) {
		return ArticleMapper.addLove(i,uId,articleId);
	}

	public int queryTotalLove(Integer articleId) {
		return ArticleMapper.queryTotalLove(articleId);
	}

	public int updateTotalLove(Integer articleId, int i) {
		return ArticleMapper.updateTotalLove(articleId,i);
	}

	public int queryLove(Integer uId, Integer articleId) {
		
		return ArticleMapper.queryLove(uId,articleId);
	}

	public int updateLove(Integer uId, Integer articleId, int i) {
		return ArticleMapper.updateLove(uId,articleId,i);
	}

	public int addArticle(String uploadfile, String articleTitle, String summry, String content, String date,
			int i, int j, int k, int l, String uId) {
	
		return ArticleMapper.addArticle(uploadfile,articleTitle,summry,content,date,i,j,k,l, uId);
	}
	
	public PageBean<List<ArticleInfo>> findAllArticleByPage(int page, int limit) {
		PageBean<List<ArticleInfo>> pb = new PageBean<>(page, limit);
		int total = ArticleMapper.findArticleCount();
		pb.setTotal(total);
		pb.setProducts(ArticleMapper.findArticleBystartLimit(pb.getStart(), limit));
		return pb;
	}

	public PageBean<List<ArticleInfo>> findGarbageArticleByPage(int page, int limit) {
		PageBean<List<ArticleInfo>> pb = new PageBean<>(page, limit);
		int total = ArticleMapper.findGarbageArticleCount();
		pb.setTotal(total);
		pb.setProducts(ArticleMapper.findGarbageArticleBystartLimit(pb.getStart(), limit));
		return pb;
	}

	//更改文章状态
	public int changeArticleStatus(String ids) {
		JSONObject jsStr = JSONObject.parseObject(ids);
		String str = (String) jsStr.get("ids");
		String status=(String) jsStr.get("status");
		String[] arr = str.split(","); // 用,分割
		return ArticleMapper.changeArticleStatus(arr,status);
	}
	//彻底删除
	public int deletePatchArticle(String ids) {
		JSONObject jsStr = JSONObject.parseObject(ids);
		String str = (String) jsStr.get("ids");
		String status=(String) jsStr.get("status");
		String[] arr = str.split(","); // 用,分割
		return ArticleMapper.deletePatchArticle(arr);
	}
	
	
}
